﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

public class DAL_tbl_shipping_master
{
    public DAL_tbl_shipping_master()
    {

    }



    public List<tbl_shipping_master> select(int SHIPPING_ID)
    {
        List<tbl_shipping_master> list = new List<tbl_shipping_master>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select SHIPPING_ID,SHIPPING_TYPE,IS_ACTIVE,CREATED_DATE,CREATED_BY,UPDATED_DATE,UPDATED_BY from tbl_shipping_master where SHIPPING_ID=@SHIPPING_ID";
        cmd.Parameters.AddWithValue("@SHIPPING_ID", SHIPPING_ID);
        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_shipping_master()
            {
                SHIPPING_ID = Convert.ToInt32(dr["SHIPPING_ID"]),
                SHIPPING_TYPE = dr["SHIPPING_TYPE"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString()
            });
        }

        return list;
    }



    public List<tbl_shipping_master> selectAll()
    {
        List<tbl_shipping_master> list = new List<tbl_shipping_master>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select SHIPPING_ID,SHIPPING_TYPE,IS_ACTIVE,CREATED_DATE,CREATED_BY,UPDATED_DATE,UPDATED_BY from tbl_shipping_master Order By SHIPPING_ID";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_shipping_master()
            {
                SHIPPING_ID = Convert.ToInt32(dr["SHIPPING_ID"]),
                SHIPPING_TYPE = dr["SHIPPING_TYPE"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString()
            });
        }

        return list;
    }



    public int insert(String SHIPPING_TYPE, bool IS_ACTIVE, DateTime CREATED_DATE, String CREATED_BY)
    {
        int i = 0;
        string sql = @"Insert into tbl_shipping_master(SHIPPING_TYPE, IS_ACTIVE, CREATED_DATE, CREATED_BY)
                        values(@SHIPPING_TYPE, @IS_ACTIVE, @CREATED_DATE, @CREATED_BY)";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@SHIPPING_TYPE", SHIPPING_TYPE);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@CREATED_DATE", CREATED_DATE);
        cmd.Parameters.AddWithValue("@CREATED_BY", CREATED_BY);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int update(int SHIPPING_ID, String SHIPPING_TYPE, bool IS_ACTIVE, DateTime UPDATED_DATE, String UPDATED_BY)
    {
        int i = 0;
        string sql = @"Update tbl_shipping_master SET SHIPPING_TYPE=@SHIPPING_TYPE, IS_ACTIVE=@IS_ACTIVE, UPDATED_DATE=@UPDATED_DATE, UPDATED_BY=@UPDATED_BY WHERE SHIPPING_ID=@SHIPPING_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@SHIPPING_ID", SHIPPING_ID);
        cmd.Parameters.AddWithValue("@SHIPPING_TYPE", SHIPPING_TYPE);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@UPDATED_DATE", UPDATED_DATE);
        cmd.Parameters.AddWithValue("@UPDATED_BY", UPDATED_BY);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int delete(int SHIPPING_ID)
    {
        int i = 0;
        string sql = "Delete FROM tbl_shipping_master WHERE SHIPPING_ID=@SHIPPING_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@SHIPPING_ID", SHIPPING_ID);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



}